from datetime import datetime, timedelta

from django.core.management import BaseCommand

from common.models.base_data import ProjectWarn, ProjectInfo


class Command(BaseCommand):
    def handle(self, *args, **kwargs):
        self.no_update_warn()

    def no_update_warn(self):
        """超过7天未更新的"""
        now_time = datetime.now()
        warn_time = now_time - timedelta(days=7)
        projects = ProjectInfo.objects.filter(update_time__lte=warn_time)
        for project in projects:
            ProjectWarn.objects.create(project_id=project.id, content='长时间未更新', type='1')
